package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.Businessinfo;
import com.ruoyi.system.domain.Shangjiatype;
import com.ruoyi.system.mapper.BusinessinfoMapper;
import com.ruoyi.system.mapper.ShangjiatypeMapper;
import com.ruoyi.system.service.IShangjiatypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.support.Convert;

/**
 * 商家类型 服务层实现
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Service
public class ShangjiatypeServiceImpl implements IShangjiatypeService
{
	private static final Logger log = LoggerFactory.getLogger(ShangjiatypeServiceImpl.class);
	@Autowired
	private ShangjiatypeMapper shangjiatypeMapper;
	@Autowired
	private BusinessinfoMapper businessinfoMapper;
	/**
     * 查询商家类型信息
     * 
     * @param businesstypeId 商家类型ID
     * @return 商家类型信息
     */
    @Override
	public Shangjiatype selectBusinesstypeById(Integer businesstypeId)
	{
	    return shangjiatypeMapper.selectShangjiatypeById(businesstypeId);
	}

	/**
     * 查询商家类型列表
     * 
     * @param businesstype 商家类型信息
     * @return 商家类型集合
     */
	@Override
	public List<Shangjiatype> selectBusinesstypeList(Shangjiatype businesstype)
	{
	    return shangjiatypeMapper.selectShangjiatypeList(businesstype);
	}
	
    /**
     * 新增商家类型
     * 
     * @param businesstype 商家类型信息
     * @return 结果
     */
	@Override
	public int insertBusinesstype(Shangjiatype businesstype)
	{
	    return shangjiatypeMapper.insertShangjiatype(businesstype);
	}
	
	/**
     * 修改商家类型
     * 
     * @param businesstype 商家类型信息
     * @return 结果
     */
	@Override
	public int updateBusinesstype(Shangjiatype businesstype)
	{
	    return shangjiatypeMapper.updateShangjiatype(businesstype);
	}

	/**
     * 删除商家类型对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteBusinesstypeByIds(String ids)
	{
		return shangjiatypeMapper.deleteShangjiatypeByIds(Convert.toStrArray(ids));
	}

	/**
	 * 根据商品ID查询所有商品类别
	 * @param businessinfoId
	 * @return 结果
	 */
	@Override
	public List<Shangjiatype> selectBusinessByShangPinId(Integer businessinfoId) {
		Businessinfo businessinfo = businessinfoMapper.selectBusinessinfoById(businessinfoId);
		List<Shangjiatype> shangjiatypes = shangjiatypeMapper.selectShangjiatypeList(null);
		for(Shangjiatype shangjiatype:shangjiatypes){
			if(shangjiatype.getShangjiatypeId()== businessinfo.getBusinesstypeId()){
				shangjiatype.setFlag(true);
				break;
			}
		}
		return shangjiatypes;
	}

}
